package com.qf.controller;

import com.qf.pojo.EmpManager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 千锋健哥
 */
@WebServlet("/test1")
public class TestController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<EmpManager> empList = new ArrayList<>();

        EmpManager emp1 = new EmpManager();
        emp1.setUserName("青龙");
        emp1.setPassWord("123123");

        EmpManager emp2 = new EmpManager();
        emp2.setUserName("白虎");
        emp2.setPassWord("123123");

        EmpManager emp3 = new EmpManager();
        emp3.setUserName("朱雀");
        emp3.setPassWord("123123");

        empList.add(emp1);
        empList.add(emp2);
        empList.add(emp3);

        List<String> strList = new ArrayList<>();
        strList.add("青龙");
        strList.add("白虎");
        strList.add("朱雀");

        //向请求中存入数据
        req.setAttribute("empList", empList);
        req.setAttribute("strList", strList);

        //请求转发到页面, 也就是跳转到页面
        //req.getRequestDispatcher("/test1.jsp").forward(req, resp);
        req.getRequestDispatcher("/test2.jsp").forward(req, resp);
    }

}
